#include "stm32f7xx_hal.h"
#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
#include "tx_timer.h"

#define SYSTEM_CLOCK  200000000
#define SYSTICK_CYCLES ((SYSTEM_CLOCK / 1000) -1)

extern void _tx_timer_interrupt(void);

void _tx_initialize_low_level(void)
{
    __set_PRIMASK(1);

    SysTick_Config(SYSTICK_CYCLES);

    HAL_NVIC_SetPriority(SVCall_IRQn, 13, 0);
    HAL_NVIC_EnableIRQ(SVCall_IRQn);

    HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
    HAL_NVIC_EnableIRQ(PendSV_IRQn);

    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(SysTick_IRQn);
}

void SysTick_Handler(void)
{
    _tx_timer_interrupt();
}